#!/usr/bin/python3
# -*- coding:utf-8 -*-
# __author__ = '__Tony__'

from fastapi import APIRouter, Depends, HTTPException, Body
from fastapi.responses import JSONResponse, Response
from database import get_db
from sqlalchemy.orm import Session
from app.yg_crm import schemas, crud, orm
from typing import List, Optional, Annotated
from utility.utility import result, RespResult, json_result_reps
from utility.myJsonHandler import orjson_dumps
from log import log
from sqlalchemy import Row

sys_router = APIRouter()

# 原生sql查询
@sys_router.post("/getDataBySql")
def getDataBySql(db: Session = Depends(get_db), sql: str = Body(embed=True,
                                                                examples=[
                                                                    {
                                                                        "sql": "select name from user",
                                                                    }
                                                                ]
                                                                )):
    log.info(sql)
    data = crud.getDataBySql(db, sql)
    return json_result_reps(data=data)
